package com.code.day10;

public class Test0 {
    public static void main(String[] args) {
        Dog dog = new Dog();
        method(dog);

        Cat cat = new Cat();
        method(cat);
    }
    public static void method(Animal  animal) {
            /* if (animal instanceof Dog){
            //向下转型
            Dog dog = (Dog) animal;
            dog.lookHome();
        }

        if (animal instanceof Cat){
            Cat cat = (Cat) animal;
            cat.eat();
            cat.catchMouse();
        }*/
        if (animal instanceof Dog dog){
            dog.eat();
            dog.lookHome();
        }

        if (animal instanceof Cat cat){
            cat.eat();
            cat.catchMouse();
        }
    }
}
